<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2018/5/18
 * Time: 16:13
 */
/**
 * 优先队列（splPriorityQueue）是基于堆实现的。
 */
$splPriorityQueue = new SplPriorityQueue();
$splPriorityQueue->insert('a', '1');
$splPriorityQueue->insert('b', '6');
$splPriorityQueue->insert('c', '3');
$splPriorityQueue->insert('d', '4');
$splPriorityQueue->insert('e', '5');

//设置元素出队模式
//SplPriorityQueue::EXTR_DATA     仅提取值
//SplPriorityQueue::EXTR_BOTH //仅提取优先级
//SplPriorityQueue::EXTR_PRIORITY 提取数组包括值和优先级
//echo '+++++++++++++++++++++++++++++++++++++仅提取值+++++++++++++++++++++++++++++++++++++++++++++++++';
//echo '<br/>';
//$splPriorityQueue->setExtractFlags(SplPriorityQueue::EXTR_DATA);
//while ($splPriorityQueue->valid()) {
//    print_r($splPriorityQueue->current());
//    echo '<br/>';
//    print_r($splPriorityQueue->next());
//}
//echo '+++++++++++++++++++++++++++++++++++++仅提取优先级+++++++++++++++++++++++++++++++++++++++++++++++++';
//echo '<br/>';
//$splPriorityQueue->setExtractFlags(SplPriorityQueue::EXTR_PRIORITY);
//while ($splPriorityQueue->valid()) {
//    print_r($splPriorityQueue->current());
//    print_r($splPriorityQueue->extract());
//    echo '<br/>';
//    print_r($splPriorityQueue->next());
//}
echo '<br/>';
echo '++++++++++++++++++++++++++++++++++++++++提取数组包括值和优先级++++++++++++++++++++++++++++++++++++++++++++++';
$splPriorityQueue->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while ($splPriorityQueue->valid()) {
    print_r($splPriorityQueue->current());
    echo '<br/>';
    print_r($splPriorityQueue->next());
}